{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 3: Maritime Inventory Routing Problems with the CIM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now introduce a new problem that takes advantage of the coherent Ising machine's ability to incorporate external fields: maritime inventory routing problems (MIRP). These problems contain an external field term, and are solved with our Amplitude Heterogeneity Correction Solver. In particular, we focus on a subset of the MIRP problems known as the vehicle routing problem with time windows (VRPTW). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Loading J and h matrices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Initialization and Imports\n",
    "import sys\n",
    "from pathlib import Path\n",
    "sys.path.append(str(Path.cwd()) + \"\\\\..\\\\\") # append lib folder to list of search directories \n",
    "\n",
    "from cim_optimizer.solve_Ising import *\n",
    "from cim_optimizer.CIM_helper import brute_force, load_adjMatrix_from_rudy\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Loading N=308 Sequence-Based VRPTW Problem"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since our MIRP examples are saved with modified start_index and preset_size, we have to overload the load_adjMatrix_from_rudy function provided in CIM_helper.py. These problems include an external field, so both J and h matrices have to be loaded from the rudy file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "inst_path_str_genVRPTW = str(Path.cwd()) + \"\\\\..\\\\instances\\\\VRPTW_TestSet\\\\\"\n",
    "\n",
    "# loading N=308 sequence-based MIRP problem\n",
    "J, h = load_adjMatrix_from_rudy(inst_path_str_genVRPTW + \"test_sb_308_f.rudy\", delimiter='\\t', index_start=1, preset_size=308)\n",
    "J = -J # flip sign to compute minima instead of maxima\n",
    "ground_state_energy = -2757.50\n",
    "time_span = 10000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "External Field Detected\n",
      "Target Ising Energy: -2757.5.\n",
      "Best Ising Energy Found: -2745.5.\n",
      "Corresponding Spin Configuration: [-1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1.  1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1.  1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1.  1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1.  1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1.\n",
      " -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1.  1. -1. -1.  1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1.  1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1.\n",
      " -1. -1. -1. -1. -1. -1. -1.  1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.\n",
      " -1. -1.].\n",
      "Time Elapsed: 11.127660036087036.\n",
      "Number of Runs Completed: 1.\n",
      "Success Probability: 0.0.\n"
     ]
    }
   ],
   "source": [
    "vrptw_test_run = Ising(J, h).solve(num_timesteps_per_run = time_span, target_energy = ground_state_energy, hyperparameters_randomtune = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAncAAACZCAYAAABNGxy5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAivklEQVR4nO3deZwlZX3v8c+vzum9p6d79p6NWWAYNtlGVkVBENAQNKBConFJwr0xJOaqSTTmGs0NJsHEeI0rJl5JiCCCqFEWQZDFMMAMy7DIMMM2G7NP9/R2tqrf/aOqe870dPd0M326unu+79erOFVP1TnnVw/VPb9+nnrqMXdHRERERCaHIO0ARERERGT0KLkTERERmUSU3ImIiIhMIkruRERERCYRJXciIiIik4iSOxEREZFJJJt2AOPFjBkzfNGiRWmHISIiInJQq1ev3unuMwfap+QusWjRIlatWpV2GCIiIiIHZWavDrZP3bIiIiIik4iSOxEREZFRUiyGpD37l5I7ERERkVEQhREP/GI9jz48aI/pmFByJyIiIjIKNm9qx92pqUl3SIOSOxEREZFRsGVjOwCtrU2pxqHkTkRERGQUtLf1YGY0NtWkGoeSOxEREZFDlM+XCMMo3tCAChEREZGJrbMjTxAYnXu6+fdr70s1FiV3IiIiIoeoc28OC4z2XV1ceOXJqcai5E5ERETkEHXszREERkNLHTv3dKcai5I7ERERkUO0ty3Xt97cUp9iJEruR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CV3IiITz1LgPOLk7AbgPnc/AegB3pkkeP8CXO7upwLfAa4p/wB3/2/ih+v+mbuf5O4vjuUJiEjlZA9+iIiIjDN3uHvRzJ4GMsCdSfnTwCLgaOB44O54diwyxLN1iMhhQMmdiMjEkwdw98jMir7v5umI+Pe6Ac+6+5lpBSgi6VG3rIjI5LMWmGlmZwKYWZWZHTfAcR3AlDGNTEQqTsmdiMgk4+4F4HLgH8zsKeLJ7M8a4NCbgD8zsyc0oEJk8tCjUEREREQmEbXciYiIiEwiSu5EREREJhEldyIiIiKTiJI7ERERkUlEyZ2IiIjIJKLkTkRERGQSUXInIiIiMokouRMRERGZRP4/+3t1lYiQ+g4AAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 720x144 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "vrptw_test_run.result.plot_spin_trajectories(plot_type=\"spins\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Due to the complex nature of the maritime inventory routing problems (when converted to an Ising problem), the coherent Ising machine has difficulty achieving the global minimum. To achieve a lower energy, we utilize hyperparameter tuning. Since we are unfamiliar with the optimal hyperparameter selection, we utilize random hyperparameter tuning as opposed to BOHB hyperparameter tuning."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "External Field Detected\n",
      "Best combination of epsilon, lambda, and scaling constant: epsilon = 0.333; lambda = 0.001; scaling constant = 10.0\n",
      "Minimum Energy Achieved with: -2730.5\n"
     ]
    }
   ],
   "source": [
    "vrptw_test_run = Ising(J, h).solve(num_timesteps_per_run = time_span, target_energy = ground_state_energy, hyperparameters_randomtune=True, suppress_statements=True)\n",
    "print(f\"Minimum Energy Achieved with: {vrptw_test_run.result.lowest_energy}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.2 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e8543a852f2c053fa96e40636049c257ee9dfe0580045d9c365f792282b251d7"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
